import requests

url = "http://0.0.0.0:5001/v1/recognition/"
data = {"text1":"人生该如何起头", "text2": "改变要如何起手"}
res = requests.post(url, data=data)

print("预测样本：", data["text1"], "|", data["text2"])
print("预测结果：", res.text)


# from flask import Flask
# from flask import request
# app = Flask(__name__)


# import torch
# # 导入中文预训练模型编码函数
# from bert_chinese_encode import get_bert_encode
# # 导入微调网络
# from finetuning_net import Net

# # 导入训练好的模型
# MODEL_PATH = "/root/ai_project/ai_doctor/model/BERT_net.pth"
# # 定义实例化模型参数
# embedding_size = 768
# char_size = 20
# dropout = 0.2

# # 初始化微调网络模型
# net = Net(embedding_size, char_size, dropout)
# # 加载模型参数
# net.load_state_dict(torch.load(MODEL_PATH))
# # 使用评估模式
# net.eval()

# @app.route('/v1/recognition/', methods=["POST"])
# def recognition():
#     # 接收数据
#     text_1 = request.form['text1']
#     text_2 = request.form['text2']
#     # 对原始文本进行编码
#     inputs = get_bert_encode(text_1, text_2, mark=102, max_len=10)
#     # 使用微调模型进行预测
#     outputs = net(inputs)
#     # 获得预测结果
#     _, predicted = torch.max(outputs, 1)
#     # 返回字符串类型的结果
#     return str(predicted.item())


# if __name__ == "__main__":
#     text_1 = "人生该如何起头"
#     text_2 = "改变要如何起手"
#     inputs = get_bert_encode(text_1, text_2, mark=102, max_len=10)
#     outputs = net(inputs)
#     # 获得预测结果
#     _, predicted = torch.max(outputs, 1)
#     # 返回字符串类型的结果
#     print(str(predicted.item()))